﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AdministradorForm
{
    public partial class ConsultarPedidosForm : PlantillaForm
    {
        public ConsultarPedidosForm()
        {
            InitializeComponent();
            dataGridView1.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            dataGridView1.Visible = false;
            //Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ObtenerTecnicoForm form = new ObtenerTecnicoForm();
            form.ShowDialog();
            textBox1.Text = form.NroEmp.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
                MessageBox.Show("Debe seleccionar un técnico para realizar la consulta", "Error en selección de técnico",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            else
            {
                ServiceReferenceAdmin.Service1SoapClient srv = new AdministradorForm.ServiceReferenceAdmin.Service1SoapClient();
                IAsyncResult res = srv.BeginListarPedidosPorTecnico(int.Parse(textBox1.Text), new AsyncCallback(ResultButton4), srv);
            }
        }

        private void ResultButton4(IAsyncResult res)
        {
            this.Invoke(new AsyncCallback(ActualizarPantalla), new object[] {res}); 
        }

        private void ActualizarPantalla(IAsyncResult res)
        { 
            ServiceReferenceAdmin.Service1SoapClient srv = (ServiceReferenceAdmin.Service1SoapClient)res.AsyncState; 
            dataGridView1.Visible = true;
            dataGridView1.DataSource = srv.EndListarPedidosPorTecnico(res);
        }
    }
}
